import React, { Component } from 'react'
import styles from './index.module.scss';
import MyNavBar from '../../components/MyNavBar';
import { WingBlank, InputItem, WhiteSpace, Button, Flex, Toast } from 'antd-mobile'

export default class register extends Component {
    constructor() {
        super()
        this.state = {
            username: "", //用户名
            password: "" //密码
        }
    }
    // 注册
    register = async () => {
        let res = await this.axios.post("/user/registered",this.state)
        console.log(res,"=====")
        if(res.data.status == 200) {
            Toast.info("恭喜你呀,注册成功",1)
            this.props.history.replace('/login')
        } else {
            Toast.info(res.data.description)
        }
    }
    render() {
        return (
            <div className={styles.root} >
                <MyNavBar title="注册页面" />
                <WhiteSpace />
                <WhiteSpace />
                <WingBlank>
                    <InputItem
                        placeholder="请输入用户名称"
                        clear
                        moneyKeyboardAlign="left"
                        onChange={val => this.setState({ username: val })}
                    >用户名</InputItem>
                    <WhiteSpace />
                    <WhiteSpace />
                    <InputItem
                        placeholder="请输入密码"
                        clear
                        onChange={val => this.setState({ password: val })}
                        moneyKeyboardAlign="left"
                    >密码</InputItem>
                    <WhiteSpace />
                    <WhiteSpace />
                    <Button type = "primary" onClick={this.register}>注册</Button>
                </WingBlank>
            </div>
        )
    }
}
